/***************************************************************************************************
  Copyright(C)   2011-2013 Global Link Comm. Co., Ltd.
  All rights reserved.
  File Name: codegenerator.h

  Description: SLCD主类，控制处理所有业务

  其中的CEPIDS宏，为在windowsXP下，让CE(路线设置工具)工具高度，用来演示路线设置情况的

  ***************************************************************************************************/
#ifndef PISPLAYER_H
#define PISPLAYER_H

#include <QWidget>
#include <QLabel>
#include <QNetworkInterface>
#include <QMessageBox>

#include "InterfaceMsg.h"
#include "mediaplayer/mplayer.h"
#include "flashplayer/flashplayer.h"
#include "bulletinboard/scrolllabel.h"
#include "playlist/playlist.h"
#include "public/xmlparser.h"
#include "public/environment.h"
#include "public/processsignalobject.h"
#include "usb/updatefile.h"
#include "tis/tis.h"
#include "ptu/udpsocketthread.h"
#include "ptu/serverwidget.h"
#include "configclass.h"

#include <signal.h>

#define DEMOVERSION 1

#ifdef _TTY_POSIX_
#include <sys/stat.h>
#include <dirent.h>

 #include "usb/updatefile.h"
#endif

#include "log4qt/propertyconfigurator.h"
#include "log4qt/log4qt.h"
#include "log4qt/consoleappender.h"
#include "log4qt/logger.h"
#include "log4qt/ttcclayout.h"
#include "log4qt/fileappender.h"

#include"log.h"

typedef struct UPDATESTRUCT{
    int updateProCount;          //可更新的源的数量,即pro文件数量
    int receUpdateCount;         //已经收到的更新源的数量
    QStringList msgList;         //第一次的更新信息,失败或者成功
    QString publishTime;         //更新源的发布时间
} UpdateStruct;

//#define _TTY_POSIX_

extern QString g_NotePath;
extern Debug_Config_s g_stDebugConfig;


namespace Ui {
    class PISPlayer;
}


class PISPlayer : public QWidget
{
    Q_OBJECT

    LOG4QT_DECLARE_QCLASS_LOGGER

public:
    explicit PISPlayer(const QString state, QWidget *parent = 0);
    ~PISPlayer();

    bool Load(QString ListName);
private:
    Ui::PISPlayer *ui;

    ProjectStruct proStruct;

    void open(QString file);
    void findLastVersion();
    qint64 countDirSize(const QString& dirPath);
    void checkNote();

    ///<
    void checkShowScreen();

    //播放初始信息
    void playLocalInfomation();
signals:
    void receUpdateConfig();

public slots:
   // void recvFromTis(char *data, qint64 len);
    void updateConfig();

    void receCheckLcdCmd(const qint8 cmd);

    void recvMsg(IMsg* msg);
    void playfinish();
    void playfinish1();

    void startToUpdate(const int proCount, const QString& publishTime);
    void updateFinish(const int condition, const ProjectStruct &project);

    void receRouteMsg_solt(const PIDS_RouteMsg&);
    void receCtlCmd_solt(const PIDS_ControlPIDS&);

    void umountUsb(const int state);

    //发送LCD状态给TIS
    void sendVideoStatusToTIS(const QList<LCDSTATUS>& status, const bool isTisSelfTest);

    void showDemoDialog();

    void processSysReboot();
    void processSysPoweroff();

    void demoMsgBoxOk();
public:
    int m_nCarNum;
    int m_nSide;
    int m_nPosition;
    QString m_updateState;                     //更新状态，－1，无更新，自然启动；0，更新失败；1，更新成功

    XmlParser       xmlParser;
    Configclass     configclass;
    UpdateStruct    updateStruct;          //更新结构体,包含更新时要用到的一些数据
    PlayList        *m_playlist;

    QString         m_updateMsg;

#ifdef CEPIDS
    UdpSocketThread *udpThread;
#else
    Tis* m_tis;
    ServerWidget    *serverWidget;
#endif


    //linux环境下的USB更新程序
#ifdef _TTY_POSIX_
    UpdateFile *updateFile;
#endif

#ifdef DEMOVERSION
    QTimer          *m_demoTimer;
    QMessageBox     *m_demoMsgBox;
#endif

    bool            m_isStart;

    // Ticker* m_scroll;
};

#endif // PISPLAYER_H
